package hu.myai.triggers.bearish;

import hu.myai.api.tick.AbstractTickProvider;
import hu.myai.api.triggers.AbstractTrigger;
import hu.myai.indicators.trendline.SupportLevelIndicator;
import hu.myai.model.TrendLineVO;
import hu.myai.model.TriggerVO;
import hu.myai.util.pool.TrendLinePool;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SupportCrossTrigger extends AbstractTrigger {

	/**
	 * The object used when logging debug,errors,warnings and info.
	 * */
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	public SupportCrossTrigger(String name, AbstractTickProvider tick) {
		super(name, tick);
	}

	public void setSupportLevelIndicatorParameter(Double parameter) {
		register(new SupportLevelIndicator(parameter));
	}

	@Override
	protected TriggerVO triggerCalculation() {

		List<TrendLineVO> supportList = TrendLinePool.getSupportInstance().getLineList(getTick().getName());

		// apply the remove
		for (TrendLineVO line : supportList) {
			double yNow = line.getY(lastTick.getTimestamp());

			// tick is above the resistance
			if (yNow > lastTick.getLow() && line.getTouch() == 0 /* && line.getTangens() < -1.25E-6 */)
				if (tickHistory.get(1).getLow() > tickHistory.get(0).getLow()) {

				TriggerVO trigger = new TriggerVO();
				trigger.setTick(lastTick);
				trigger.setTradeType(TriggerVO.BUY_ONMARKET);

				log.debug(trigger.toString());
				return trigger;
			}
		}
		return null;
	}
}
